package com.cqr.studentmanager.interceptors;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

//处理国际化问题，写一个国际化处理器
public class MyLocaleResolver implements LocaleResolver {
    //返回国际化信息
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        //获取请求参数
        String language = httpServletRequest.getParameter("l");
        Locale locale = Locale.getDefault();//获得默认的信息

        //判断，如果请求的参数不为空
        if (!StringUtils.isEmpty(language)){
            //拿到请求参数,分割请求参数[en,US]
            String[] split = language.split("_");
            locale = new Locale(split[0], split[1]);
        }

        return locale;
    }

    //不用写
    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }



}
